<?php
require_once(dirname(__FILE__)."/../inc/common.php");
/*******************************************************************************************
'*******************************************************************************************/
if (paramset == 0 || runMode == "forgedStatic"){
    $paras = replaceStr(QUERY_STRING, fileSuffix, "");
    if (strpos($paras, "-") > 0) {
	    $parasArray = explode("-", $paras);
	    if (count($parasArray == 2)) {
		    $m_id = $parasArray[0]; $id = $parasArray[1]; $from = $parasArray[2];
	    } else {
		    echoSaveStr("null");exit();
	    }
    } else {
	    $m_id = intval($paras) ; $id = "" ; $from = "";
    }
}else{
	$m_id = getForm(paramid,"both") ; $id = getForm(parampage,"both") ; $from = getForm(paramindex,"both");
}
if (empty($m_id)) {
	echoSaveStr("null");exit();
} else {
	if (is_numeric($m_id)) {
		$m_id=intval($m_id);
	} else { 
	    echoSaveStr("safe");exit();
	}
}
Play($m_id);
echoPlay($m_id);

function echoPlay($vId) {
	global $id,$from,$t1;
	if (isAlertWin == 1) $z = "openplay.html"; else  $z = "play.html";
	$x = DJCMS_TEMPLATE.$z;
	$row = DB::fetch_first("SELECT m_id,m_type,m_name,m_state,m_pic,m_hit,m_actor,m_des,m_topic,m_color,m_addtime,m_publishyear,m_publisharea,m_commend,m_note,m_keyword ,m_digg,m_tread,m_playdata,m_downdata,m_enname,m_datetime,m_director,m_lang,m_score,m_count FROM ".DB::table('data')." WHERE m_recycle=0 AND m_id='$vId'");
	if (!is_array($row)) { OutNotFound("play");}
	$vType = $row['m_type'];$venname = $row['m_enname'];$vdatetime = $row['m_datetime'];
	if (iscache == '1'){
       checkCourt($vType);
    }
	if (strpos(" ,".getHideTypeIDS().",", ",".$vType.",") > 0) { OutNotFound("play");}
	$contentLink = getContentLink($vType,$vId,$venname,$vdatetime,"link");
	$typeText = getTypeText($vType);djcms::$currentTypeId=$vType;
	$typeFlag = "parse_play_" ;$cacheName = $typeFlag.$vType;
	if (cacheStart == 1) {
		if (djcms::$content = memory('get', $cacheName)) {
        } else {
            parsePlayPart($x);
            memory('set', $cacheName, djcms::$content);
        }
	} else {
			parsePlayPart($x);
	}
	djcms::paresPreNextVideo($vId, "play", $vType);
	djcms::parseVideo($row);$playORdownData=$row['m_playdata'];
	if (IsFromSort==1) $playORdownData=ResetFromSort($playORdownData);
	$content = replaceStr(djcms::$content,"{playpage:playurlinfo}","<script>var VideoListJson=".PlayData2Json($playORdownData).",urlinfo='http://'+document.domain+'".getPlayLink2($vType,$vId,$venname,$vdatetime,"<from>","<pos>")."';</script>");
	$content = replaceStr($content,"{playpage:id}", $row['m_id']);
	$content = replaceStr($content,"{playpage:typeid}", $row['m_type']);
	$content = replaceStr($content,"{playpage:desktopurl}","/".sitePath."desktop.php?name={playpage:encodename}&url=".urlencode($contentLink));
	$content = replaceStr($content,"{playpage:encodename}",urlencode($row['m_name']));
	$content = replaceStr($content,"{playpage:lang}",$row['m_lang']);
	$content = replaceStr($content,"{playpage:nolinkkeywords}", $row['m_keyword']);
	if (isExistStr($content, "{playpage:keywords}")) $content = replaceStr($content, "{playpage:keywords}", getKeywordsList($row['m_keyword'],"&nbsp;&nbsp;"));
	if (isExistStr($content, "{playpage:part}")) $content = replaceStr($content, "{playpage:part}", getPartName($row['m_playdata'], $id, $from));
	if (!empty($row['m_pic'])) {
		if (isExistStr($row['m_pic'], '://')) {
		    $content = replaceStr($content,"{playpage:pic}",$row['m_pic']);
		} else {
		    $content = replaceStr($content,"{playpage:pic}","/".sitePath.$row['m_pic']);
		}
	} else {
		$content = replaceStr($content,"{playpage:pic}","/".sitePath."pic/nopic.gif");
	}
	$content = replaceStr($content,"{playpage:director}",getKeywordsList($row['m_director'],"&nbsp;&nbsp;"));
	$content = replaceStr($content,"{playpage:publishtime}",$row['m_publishyear']);
	$content = replaceStr($content,"{playpage:publisharea}",$row['m_publisharea']);
	$content = replaceStr($content,"{playpage:state}",$row['m_state']);
	$content = replaceStr($content,"{playpage:diggnum}",$row['m_digg']);
	$content = replaceStr($content,"{playpage:treadnum}",$row['m_tread']);
	$content = replaceStr($content,"{playpage:scorenum}",$row['m_count']);
	$content = replaceStr($content,"{playpage:score}",$row['m_score']);
	$content = replaceStr($content,"{playpage:commend}",$row['m_commend']);
	if (getcookie("u_name")){
		$content = replaceStr($content,"{playpage:username}",getcookie("u_name"));
	} else {
		$content = replaceStr($content,"{playpage:username}","");
	}
	$content = replaceStr($content,"{playpage:link}",$contentLink);
	$content = replaceStr($content,"{playpage:url}","http://".siteUrl.$contentLink);
	$content = replaceStr($content,"{playpage:textlink}",$typeText."&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href='".$contentLink."'>".$row['m_name']."</a>");
	$playLink=getPlayLink2($vType,$row['m_id'],$row['m_addtime'],$row['m_enname'],0,0);
	if (isAlertWin==1){ $playLink="javascript:openWin('".$playLink."',".($alertWinW+10).",".($alertWinH+55).",250,100,1)";}
	$content = replaceStr($content,"{playpage:playlink}",$playLink);
	djcms::$content = replaceStr($content,"{playpage:player}","<iframe border=\"0\" src=\"/".sitePath."js/play.html\" marginWidth=\"0\" frameSpacing=\"0\" marginHeight=\"0\" frameBorder=\"0\" noResize scrolling=\"no\" width=\"100%\" height=\"488\" vspale=\"0\" style=\"z-index:9998;\"></iframe>");
	djcms::parsePlayList($vType,$vId,$venname,$vdatetime,$row['m_playdata'],"play");
	djcms::parsePlayList($vType,$vId,$venname,$vdatetime,$row['m_downdata'],"down");
	djcms::parseIf();
	echo replaceStr(djcms::$content,"{yh:runinfo}",getRunTime($t1)) ;
}

function parsePlayPart($x) {
	djcms::$content=loadFile($x);
	djcms::parsePlayPageSpecial();
	djcms::parseTopAndFoot();
	djcms::parseSelf();
	djcms::parseGlobal();
	$typename = explode(",", getTypeNameTemplateArrayOnCache(intval(djcms::$currentTypeId)));
	djcms::$content = replaceStr(replaceStr(djcms::$content,"{yh:currenttypeid}",djcms::$currentTypeId),"{playpage:typeid}",djcms::$currentTypeId);
	if (isExistStr(djcms::$content,"{playpage:typename}")) djcms::$content = replaceStr(djcms::$content,"{playpage:typename}",$typename[0]);
    if (isExistStr(djcms::$content,"{playpage:typelink}")) djcms::$content = replaceStr(djcms::$content,"{playpage:typelink}",getTypeLink(djcms::$currentTypeId));
	if (isExistStr(djcms::$content,"{playpage:upid}")) djcms::$content = replaceStr(djcms::$content,"{playpage:upid}",$typename[2]);
	djcms::parseMenuList("");
	djcms::parseNewsList();
	djcms::parseAreaList();
	djcms::parseVideoList();
	djcms::parseTopicList();
}

function getPartName($playData,$m,$n) {
	$PartName='';
	$playDataarray1=explode("$$$",$playData);
	if (strpos($playDataarray1[$m],"$$")>0) {
		$playDataarray2=explode("$$",$playDataarray1[$m]);
		$playDataarray3=explode("#",$playDataarray2[1]);
		if (strpos($playDataarray3[$n],"$")>0) {
			$playDataarray4=explode("$",$playDataarray3[$n]);
			$PartName=$playDataarray4[0];
		}
	}
    return $PartName;
}
?>
